<template>
    <!--我的库存-->
    <div class="app-container">
      <CStockDetail ref="openCStockDetail"/>
      <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px" :label-position="labelPosition">
        <el-form-item label="仓库" prop="spckmc">
          <el-select
              v-model="queryParams.spckmc"
              placeholder="请选择"
              clearable
              filterable
              :loading="selectWarehouse15Loading || loading"
          >
              <el-option
                  v-for="item in selectWarehouse15List"
                  :key="item.spckid"
                  :label="item.spckmc"
                  :value="item.spckid"
              />
          </el-select>
        </el-form-item>
        <el-form-item label="物品规格" prop="spzs">
          <el-input
            v-model="queryParams.spzs"
            placeholder="请输入物品规格"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item label="批号" prop="spbh">
          <el-input
            v-model="queryParams.spbh"
            placeholder="请输入批号"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item label="柜号" prop="spgh">
          <el-input
            v-model="queryParams.spgh"
            placeholder="请输入柜号"
            clearable
             @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item label="类型" prop="spdms">
          <el-select
              v-model="queryParams.spdms"
              placeholder="请选择类型"
              multiple
              clearable
          >
              <el-option
                  v-for="item in type"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
              />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="loading"
        :data="goodsOverviewList"
      >
        <af-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="left" width="100">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="historyDetail(scope.row)"
              v-hasPermi="['zhcloud:sjzl:list']"
            >查看明细</el-button>
          </template>
        </af-table-column>
        <af-table-column prop="spdm" label="类型" fixed="left"></af-table-column>
        <af-table-column prop="spzs" label="物品规格"></af-table-column>
        <af-table-column prop="spbh" label="批号"></af-table-column>
        <af-table-column prop="spgh" label="柜号"></af-table-column>
        <af-table-column prop="wpggA" label="纱支"></af-table-column>
        <af-table-column prop="spcd" label="品牌"></af-table-column>
        <af-table-column prop="spjsl" label="单重(KG)"></af-table-column>
        <af-table-column prop="spjs" label="件数"></af-table-column>
        <af-table-column prop="spsl" label="重量(吨)"></af-table-column>
        <af-table-column prop="sptm" label="客户条码"></af-table-column>
        <af-table-column prop="spckmc" label="仓库"></af-table-column>
        <af-table-column prop="ckcw" label="仓位"></af-table-column>
        <af-table-column prop="ssrqid" label="入仓日期"></af-table-column>
        <af-table-column prop="days" label="结存天数"></af-table-column>
        <af-table-column prop="gjdj" label="估值单价"></af-table-column>
      </el-table>
       <pagination
          v-show="total>0"
          :total="total"
          :page.sync="pageNum"
          :limit.sync="pageSize"
          @pagination="getList"
        />
    </div>
  
  </template>
  
  <script>
  import { getGoodsOverviewList } from "@/api/storage/dataOverview/goodsOverview"
  import { selectWarehouse15 } from "@/api/storage/warehouse"
  import CStockDetail from './detail.vue'

  export default {
    name: "CStock",
    components:{ CStockDetail },
    data() {
      return {
        // 显示搜索条件
        showSearch: true,
        //对齐
        labelPosition: "right",
        //加载列表
        loading: true,
        //仓库加载
        selectWarehouse15Loading: true,
        //审核状态
        type:[{
          value: "普通",
          label:"普通"
        },{
          value: "担保",
          label:"担保"
        },{
          value: "冻结",
          label:"冻结"
        }],
        goodsOverviewDate:'',
        // 查询参数
        queryParams: {
          ally: "",
          ckcw1: "",
          day: "",
          dayi: "",
          gaoling: "",
          jqcz: "",
          khmc: "",
          spbh: "",
          spbz: "",
          spcd: "",
          spckmc: "",
          //spdm: "",
          spdms:[],
          spgh: "",
          spmc: "",
          sptm: "",
          spzs: "",
          ssrqid: "",
          wbdh: "",
          downloadType:"json"
        },
        //批量审核数据
        selection:[],
        // 货物入仓列表
        goodsOverviewList: [],
        //仓库列表
        selectWarehouse15List:[],
        //客户列表
        selectClient5List: [],
        //页数
        pageSize: 10,
        //页码
        pageNum:1,
        // 总条数
        total: 0,
      };
    },
    beforeRouteEnter(to, from, next) {
      const params = to.params
      next(vm => {   
        if(Object.keys(params).length > 0) {
          if(to.params.refresh == true) {
            vm.getList()
          }
        }
      })
    },
    created() {
      const user = this.$store.getters.user
      this.getWarehouse()
      if(user.shopName) {
        this.queryParams.khmc = user.shopName
        this.getList()
      }
    },
    methods: {
      /**获取仓库 */
      getWarehouse() {
        this.selectWarehouse15Loading = true
        selectWarehouse15({}).then(response => {
          this.selectWarehouse15List = response.data
          this.selectWarehouse15Loading = false
        });
      },
      /** 查询货物入仓列表 */
      getList() {
        this.loading = true
        getGoodsOverviewList(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
          this.goodsOverviewList = response.rows;
          this.total = response.total;
          this.loading = false
        });
      },
  
      /**查看明细 */
      historyDetail(data) {
        this.$refs.openCStockDetail.open(data)
      },
  
      /**enter键触发 */
      enterClick(e) {
        this.getList()
      },
      /** 刷新数据*/
      refresh() {
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.reset()
        this.getWarehouse()
        this.getList()
      },
      reset() {
        Object.assign(this.$data, this.$options.data())
      },
    }
  };
  </script>
  